package service.impl;

import dao.NewsDao;
import dao.impl.NewsDaoImpl;
import dao.impl.NewsOracleImpl;
import factory.SimpleDaoFactory;
import pojo.News;
import service.NewsService;

/**
 * @version v1.0
 * @Author JieGe
 * @Create 2024-11-30 - 9:37
 */
public class NewsServiceImpl implements NewsService {

    // new NewsOracleImpl() 依赖对象
    // 依赖倒置原则：依赖于约定而不依赖于具体实现。
    // 传递依赖对象的两种方式：利用构造方法、利用set方法
    private NewsDao newsDao; // 接口的引用对象， 依赖于约定，而不依赖于具体的实现
    public void setNewsDao(NewsDao newsDao) {
        this.newsDao = newsDao;
    }

//    public NewsServiceImpl(NewsDao newsDao) {
//        this.newsDao = newsDao;
//    }

    @Override
    public int save(News news) {
        return newsDao.save(news);
    }

    public static void main(String[] args) {
        // NewsServiceImpl service = new NewsServiceImpl(new NewsOracleImpl());
        // 由测试类来创建具体实现(依赖对象)
        // service.setNewsDao(new NewsOracleImpl());

    }


}
